package com.hq.ims.data.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.annotation.ChangeRecord;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.BusiInfo;
import com.hq.ims.data.entity.CompanyServiceArea;
import com.hq.ims.data.entity.CompanyServiceType;
import com.hq.ims.data.entityenum.*;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20241025
 */
@Mapper
public interface BusiInfoMapstruct {

    BusiInfoMapstruct INSTANCE = Mappers.getMapper(BusiInfoMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    BusiInfoVo toBusiInfoVo(BusiInfo source);

    default List<BusiInfoVo> toBusiInfoVoList(List<BusiInfo> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toBusiInfoVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class BusiInfoVo extends BusiInfo {

        @ApiModelProperty(value = "产业标记指派")
        private List<BusiIndustryAssignMapstruct.BusiIndustryAssignVo> busiIndustryAssignList;

        @ApiModelProperty(value = "派生信息列表")
        private List<BusiInfo> derivativeList;

        @ApiModelProperty(value = "推送公司")
        private String pushCompany;

        @ApiModelProperty(value = "施工方重复数")
        private long constructionRepeatCount = 0;

        @ApiModelProperty(value = "施工方重复率")
        private BigDecimal constructionRepeatRate = new BigDecimal(0);

        @ApiModelProperty(value = "业主方重复数")
        private long ownerRepeatCount = 0;

        @ApiModelProperty(value = "业主方重复率")
        private BigDecimal ownerRepeatRate= new BigDecimal(0);

        @ApiModelProperty(value = "项目名称重复数")
        private long nameRepeatCount = 0;

        @ApiModelProperty(value = "项目名称重复率")
        private BigDecimal nameRepeatRate= new BigDecimal(0);

        @ApiModelProperty(value = "项目位置重复数")
        private long placeRepeatCount = 0;

        @ApiModelProperty(value = "项目位置重复率")
        private BigDecimal placeRepeatRate= new BigDecimal(0);

        @ApiModelProperty(value = "是否源信息")
        private EnumRootInformation rootInformationEnum;

        @ApiModelProperty(value = "产业标记")
        private List<CompanyServiceType> types;

        @ApiModelProperty(value = "服务地区")
        private List<CompanyServiceArea> areas;

    }

    @ApiModel(value = "行级权限对象")
    @Data
    class BusiInfoRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public BusiInfoRowAuthVo(BusiInfo entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
        }

    }


    @ApiModel(value = "计算相似度数据对象")
    @Data
    class CalcSimilarityDataObj {

        @ApiModelProperty(value = "经营信息管理ID")
        private String busiInfoId;

        @ApiModelProperty(value = "项目名称")
        private String projectName;

        @ApiModelProperty(value = "项目地址名称")
        @TableField(value = "project_address_name")
        private String projectAddressName;

        @ApiModelProperty(value = "业主方公司名称")
        private String ownerCompanyName;

        @ApiModelProperty(value = "施工方公司名称")
        private String constructionName;

    }


    @ApiModel(value = "计算相似单个类型结果")
    @Data
    class CalcSimilarityDataASurnameTypeResult {

        /**
         * 计算重复类型
         */
        private EnumBusinessRepeatType calcRepeatType;

        /**
         * 权重1-10
         */
        private BigDecimal weight;

        /**
         * 单个字段的相似率
         */
        private BigDecimal similarityRate;

        /**
         * 权重相拟率
         */
        private BigDecimal weightSimilarityRate;

        /**
         * 被比较数据的ID
         */
        private String beCompareDataId;

        /**
         * 被比较数据的值
         */
        private String beCompareDataValue;

        /**
         * 比较数据的值
         */
        private String compareValue;

    }

    @ApiModel(value = "计算相似单个类型结果")
    @Data
    class CalcSimilarityDataResult {

        /**
         * 相拟度率
         */
        private BigDecimal similarityRate;

        /**
         * 被比较数据的ID
         */
        private String beCompareDataId;

        /**
         * 行数据结果相拟度
         */
        private List<CalcSimilarityDataASurnameTypeResult> resultTypeList;

    }



    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {
        @ApiModelProperty(value = "项目名称")
        private String projectName;

        @ApiModelProperty(value = "信息类型")
        private EnumBusinessTypeStatus infoType;

        @ApiModelProperty(value = "发布时间开始时间")
        private LocalDateTime publishTimeStart;

        @ApiModelProperty(value = "发布时间结束时间")
        private LocalDateTime publishTimeEnd;

        @ApiModelProperty(value = "审核状态")
        private EnumAuditStatus auditStatus;

        @ApiModelProperty(value = "app查询未审核")
        private Boolean appUnaudited = false;

        @ApiModelProperty(value = "发布状态")
        private EnumPublishStatus publishStatus;

        @ApiModelProperty(value = "产业标记")
        private List<String> industryAssigns;

        @ApiModelProperty(value = "接受状态")
        private EnumReceiveStatus acceptStatus;

        @ApiModelProperty(value = "组织范围上级组织Id")
        private String parentOrgId;

        @ApiModelProperty(value = "组织Id")
        private String orgId;

        @ApiModelProperty(value = "重复率")
        private Double repetitionRate;

        @ApiModelProperty(value = "省份")
        private String province;

        @ApiModelProperty(value = "地区")
        private String city;

        @ApiModelProperty(value = "发布人")
        private String publisherId;

        @ApiModelProperty(value = "发布人")
        private String publisher;

        @ApiModelProperty(value = "信息来源")
        private EnumRootInformation rootInformationEnum;

        @ApiModelProperty(value = "项目阶段")
        private EnumProjectPhase projectStage;

        @ApiModelProperty(value = "排序")
        private EnumBusiInfoOrder orderBy;

        @ApiModelProperty(value = "公司名称")
        private String companyName;
    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "数据ID不能为空", groups = {VdEdit.class})
        @ApiModelProperty(value = "数据ID")
        private String busiInfoId;

        @ApiModelProperty(value = "重复率")
        private Double repetitionRate;

        @NotBlank(message = "项目名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "项目名称")
        @ChangeRecord
        private String projectName;

        @NotNull(message = "信息类型不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "信息类型")
        @ChangeRecord
        private EnumBusinessTypeStatus infoType;

        @ApiModelProperty(value = "信息来源")
        private String infoSource;

        @NotBlank(message = "项目地址名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "项目地址名称")
        @ChangeRecord
        private String projectAddressName;

        @NotBlank(message = "经度不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "经度")
        @ChangeRecord
        private String longitude;

        @NotBlank(message = "纬度不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "纬度")
        @ChangeRecord
        private String latitude;

        @ApiModelProperty(value = "项目阶段")
        @ChangeRecord
        private EnumProjectPhase projectStage;

        @NotBlank(message = "省份不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "省份")
        @ChangeRecord
        private String province;

        @ApiModelProperty(value = "省份编码")
        @TableField(value = "province_code")
        private String provinceCode;

        @NotBlank(message = "城市不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "城市")
        @ChangeRecord
        private String city;

        @ApiModelProperty(value = "市区编码")
        @TableField(value = "city_code")
        private String cityCode;

        @ApiModelProperty(value = "联系人")
        private String contactPerson;

        @ApiModelProperty(value = "联系方式")
        private String contactInfomation;

        @NotBlank(message = "业主方公司名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "业主方公司名称")
        @ChangeRecord
        private String ownerCompanyName;

        @ApiModelProperty(value = "施工方公司名称")
        @ChangeRecord
        private String constructionName;

        @NotNull(message = "预计产值规模不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "预计产值规模")
        @ChangeRecord
        private BigDecimal outputScale;

        @ApiModelProperty(value = "项目备注")
        @ChangeRecord
        private String projectRemark;

        @ApiModelProperty(value = "发布人")
        private String publisher;

        @ApiModelProperty(value = "发布人id")
        private String publisherId;

        @ApiModelProperty(value = "发布状态")
        @TableField(value = "publish_status")
        private EnumPublishStatus publishStatus;

        @ApiModelProperty(value = "审核人")
        @TableField(value = "audit_user_id")
        private String auditUserId;

        @ApiModelProperty(value = "发布时间")
        private LocalDateTime publishTime;

        @ApiModelProperty(value = "审核状态")
        private EnumAuditStatus auditStatus;

        @ApiModelProperty(value = "审批时间")
        private LocalDateTime auditTime;

        @ApiModelProperty(value = "审核备注")
        private String auditRemark;

        @ApiModelProperty(value = "接受状态")
        private EnumReceiveStatus acceptStatus;

        @ApiModelProperty(value = "组织机构ID")
        private String orgId;

        @ApiModelProperty(value = "组织机构名称")
        private String orgName;

        @ApiModelProperty(value = "父ID(顶经则为0)")
        private String parentId;

        @ApiModelProperty(value = "根节点ID")
        private String rootId;

        @ApiModelProperty(value = "产业标记")
        private String industryAssign;

        @ApiModelProperty(value = "企业分成规则")
        @ChangeRecord
        private BigDecimal companyDivideIntoRuleValue;

        @ApiModelProperty(value = "资金来源")
        @ChangeRecord
        private String fundingSource;

        @ApiModelProperty(value = "招标获取截止时间")
        @ChangeRecord
        private LocalDateTime tenderClosingDate;

        @ApiModelProperty(value = "招标截止时间")
        @ChangeRecord
        private LocalDateTime deadlineForBidding;

        @ApiModelProperty(value = "项目规模")
        @ChangeRecord
        private String projectScale;

        @ApiModelProperty(value = "工期要求")
        @ChangeRecord
        private String durationRequired;

        @ApiModelProperty(value = "招标范围")
        @ChangeRecord
        private String tenderScope;

        @ApiModelProperty(value = "资质要求")
        @ChangeRecord
        private String qualifications;

        @ApiModelProperty(value = "招标控制价")
        @ChangeRecord
        private BigDecimal tenderControlPrice;

        @ApiModelProperty(value = "保证金金额")
        @ChangeRecord
        private BigDecimal bond;

        @ApiModelProperty(value = "保证金缴纳截止时间")
        @ChangeRecord
        private LocalDateTime bondEndTime;

        @ApiModelProperty(value = "创建时间")
        private LocalDateTime createDateTime;

        @ApiModelProperty(value = "更新时间")
        private LocalDateTime updateDateTime;

        @ApiModelProperty(value = "是否删除")
        private Boolean isDel;

        @ApiModelProperty(value = "创建用户名称")
        private String createUserName;

        @ApiModelProperty(value = "更新用户名称")
        private String updateUserName;

        @ApiModelProperty(value = "乐观锁")
        private Integer version;

        @ApiModelProperty(value = "产业标记指派表")
        private List<BusiIndustryAssignMapstruct.SaveVo> busiIndustryAssignList;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
